<template>
  <div>
    <mavon-editor ref="md" @imgAdd="imgadd" style="min-height: 400px"/>
  </div>
</template>

<script>

import {mavonEditor} from 'mavon-editor'
// 引入编辑器样式
import 'mavon-editor/dist/css/index.css'

export default {
  name: 'Test',
  data() {
    return {
      data1: '',
      form: {content: ''},
      token: ''
    }
  },
  methods: {
    change(value, render) {
      this.form.content = render
    },
    imgadd(pos, $file) {
      alert(11111)
      var formData = new FormData()
      formData.append('token', this.token)
      formData.append('file', $file)
      this.axios.post('http://up-z1.qiniu.com/', formData)
        .then(res => {
          console.log(res)
          this.$refs.md.$img2Url(pos, 'http://qyfdsxcmi.hb-bkt.clouddn.com/' + res.data.key)
        })
    },
    get_qinniu_token() {
      this.axios.get('sadmin/qinniu/')
        .then(res => {

          this.token = res.data.token
          alert(res.data.token)
        })
    },
  },
  mounted() {
    this.get_qinniu_token()
  },
  components: {
    mavonEditor
  },
  created() {

  }
}
</script>

<style scoped>

</style>
